<?php

namespace app\admin\model;

use app\common\model\TimeModel;

class Community extends TimeModel
{
    protected $name = "community";
    protected $deleteTime = false;

    /**
     * 获取社区列表
     * @return array|string[]
     */
    public static function getCommunityList()
    {
        $list = self::field('id,name')->select()->toArray();
        return $list;
    }

    /**
     * 获取社区列表2
     * @return array|string[]
     */
    public static function getCommunityList2($flag = false)
    {
        $list = self::column('name','id');
        if ($flag) {
            $list[0] = '无';
        }
        return $list;
    }

    /**
     * 社区名查ID
     * @param string $name 社区名
     * @return int|mixed
     */
    public static function getNameById(string $name)
    {
        return self::where('name', $name)->value('id') ?? 0;
    }

}